﻿using System.Text.Json;

namespace 设备报警系统客户端
{
    public partial class 日志 : Form
    {
        // 静态变量来存储MyForm的实例  
        private static 日志 _instance;

        // 私有构造函数，防止外部通过new创建实例  
        private 日志()
        {
            InitializeComponent();
        }

        // 公共静态方法来获取MyForm的实例  
        // 如果实例不存在，则创建并显示它；如果已存在，则激活该实例  
        public static void ShowForm()
        {
            if (_instance == null || _instance.IsDisposed)
            {
                _instance = new 日志();
                _instance.Show();
            }
            else
            {
                _instance.Activate(); // 将已存在的实例带到前台  
            }
        }

        private void 日志_Load(object sender, EventArgs e)
        {
            try
            {
                //在运行设备刷新
                string req = Basic.HttpGet("/Currency/Logs");

                var runningState = JsonSerializer.Deserialize<List<string>>(req);

                textLog.Text = $"客户端编号：{Basic.GetSystemId()}\r\n\r\n";

                foreach (var item in runningState)
                {
                    textLog.Text += $"{item} \r\n\r\n";
                }
            }
            catch (Exception)
            {

            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                //在运行设备刷新
                string req = Basic.HttpGet("/Currency/Logs");

                var runningState = JsonSerializer.Deserialize<List<string>>(req);

                textLog.Text = $"客户端编号：{Basic.GetSystemId()}\r\n\r\n";

                foreach (var item in runningState)
                {
                    textLog.Text += $"{item} \r\n\r\n";
                }
            }
            catch (Exception)
            {

            }
        }
    }
}
